Imports System.Windows.Forms

Friend Class frmBDialog
    Sub New(ByVal question As String, ByVal Caption As String, ByVal value As String)
        Me.InitializeComponent()

        Me.Text = Caption
        Me.lblMain.Text = question
        Me.tbMain.Text = value
        Me.tbMain.Focus()
    End Sub
    Sub New(ByVal question As String, ByVal Caption As String)
        Me.InitializeComponent()

        Me.Text = Caption
        Me.lblMain.Text = question
        Me.tbMain.Focus()
    End Sub
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        If tbMain.Text <> "" Then
            Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Else
            Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        End If
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub
    Friend ReadOnly Property Value() As String
        Get
            Return tbMain.Text
        End Get
    End Property

    Private Sub tbMain_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbMain.KeyPress
        If e.KeyChar = Chr(13) Then
            Me.OK_Button.PerformClick()
        End If
    End Sub

    Private Sub BDialog_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        Me.tbMain.Focus()
        Me.tbMain.SelectionLength = 0
        Me.tbMain.SelectionStart = Me.tbMain.Text.Length
    End Sub
End Class
